Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Allow DAGs to silence only errors matching predicate #654

Merged
merged 3 commits into from
Aug 24, 2022

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Aug 11, 2022

Fixes

Fast follow from #643 to implement a suggestion by @sarayourfriend

⚠️ Because this introduces a breaking change to the configuration variable, we must make sure the variable is not configured in production before merging. If it is configured, we need to make sure no affected DAGs (check_silenced_dags, any silenced DAGs) are running while we deploy these changes and update the variable interface. Discussion. ⚠️

Description

#643 introduced an Airflow variable (silenced_slack_alerts) that allows configuring a DAG to skip Slack reporting of errors. The implementation in that PR only allows for skipping Slack reporting for all error messages, but in reality we're unlikely to want this behavior. It's much safer to be able to silence specific known errors.

This PR changes the shape of the silenced_slack_alerts:
Screen Shot 2022-08-10 at 7 10 51 PM

For each dag_id you must now provide both an issue and a list of errors. A slack alert will not be sent if it matches any of the predicates in the errors list for the given DAG.

Because our on_failure_callback includes information like the ExceptionType and task id in the message, we can use this to selectively silence messages matching those parameters as well.

Testing Instructions

  • Create an Airflow variable named silenced_slack_alerts in the Admin > Variables UI. For my tests I used this configuration:
{
  "audio_data_refresh": {
      "issue": "https://github.com/WordPress/openverse-catalog/issues/438",
      "errors": ["A test exception"]
  }
}
  • For the DAGs you've configured above, force an error to be thrown by editing the code to manually raise one. Make sure that it includes the configured predicate.
  • Run the DAG and verify that you can see a message in the logs saying Skipping Slack alert for <dag_id>.
  • Play around with your test error and the errors configuration to test that errors that do not match any of the predicates are still reported to Slack.

Now test check_silenced_dags DAG:

  • Edit your configuration to link to a GH issue that is closed. Run the DAG and verify you get a Slack alert indicating that the alerts can be turned back on.
  • Edit your configuration to link to a GH issue that is open. Run the DAG and verify you do not see a Slack alert.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@stacimc stacimc added 🟩 priority: low Low priority and doesn't need to be rushed ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository labels Aug 11, 2022
@stacimc stacimc requested a review from a team as a code owner August 11, 2022 02:19
@stacimc stacimc self-assigned this Aug 11, 2022
@stacimc stacimc requested review from krysal and obulat August 11, 2022 02:19
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question for airflow deployment stuff: when merging this PR change, what is the process for handling the change in the variable interface? These changes are not backwards compatible with the existing variable interface, so this dag would crash on a type error (I think). Is the process to first turn the DAG off in production, then in any order, merge this PR and update the variable to the new interface, then re-enable the DAG after the new DAG code has been pulled?

@stacimc
Copy link
Contributor Author

stacimc commented Aug 11, 2022

General question for airflow deployment stuff: when merging this PR change, what is the process for handling the change in the variable interface? These changes are not backwards compatible with the existing variable interface, so this dag would crash on a type error (I think). Is the process to first turn the DAG off in production, then in any order, merge this PR and update the variable to the new interface, then re-enable the DAG after the new DAG code has been pulled?

In general, yes. In this case this would mean turning off check_silenced_dags and making sure no actually configured silenced DAGs are running (or temporarily reenabling alerting for them).

Because we don't have the variable set up yet, we should be fine to simply merge this as a fast-follow -- but I'll update the PR description to make sure we double-check that before merging.

Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I was worried we'd have to match on exception text, which would be an issue for things like KeyErrors where the error text is only the missing key and nothing else 😶 Hard to know that ahead of time! But since we're doing a simple substring match and we include the exception type in the slack message, we can match that too 🥳 I used KeyError as my errors value and raised a KeyError within the DAG, it worked exactly as expected 🚀

I have one suggestion regarding string comparisons.

openverse_catalog/dags/common/slack.py Outdated Show resolved Hide resolved
Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎊 🤖

Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@stacimc stacimc merged commit 03ce84f into main Aug 24, 2022
@stacimc stacimc deleted the update/silenced-dags-to-check-error-predicate branch August 24, 2022 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟩 priority: low Low priority and doesn't need to be rushed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants